﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Rendering;
using NetCoreCMS.Common;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;
namespace NetCoreCMS.Web.Areas.Admin.Controllers.Dialog
{
    public class Dialog_ExpressController : ManageController
    {
        private const string WEB_VIEW = "~/Areas/Admin/Views/Dialog/dialog_express.cshtml";
        private string order_no = string.Empty;
        public IOrdersService _orders { get; set; }
        public IExpressService _express { get; set; }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            order_no = HttpContext.Request.Query["order_no"].FirstOrDefault();
            if (order_no == "")
            {
                JscriptMsg("传输参数不正确！", "back");
                return;
            }
            if (!_orders.Exists(order_no))
            {
                JscriptMsg("订单不存在或已被删除！", "back");
                return;
            }
            ViewBag.OrderNo = this.order_no;
        }
        //
        // GET: /admin/Dialog_Express/

        public ActionResult Index()
        {
            ShowInfo(order_no);
            return View(WEB_VIEW);
        }

        #region 赋值操作=================================
        private void ShowInfo(string _order_no)
        {
            Orders model = _orders.GetModel(_order_no);
            ViewData["model"] = model;
            List<SelectListItem> expressListItems = new List<SelectListItem>() {
            new SelectListItem(){ Text="请选择配送方式", Value="" }
         };
            var dt = _express.GetList();
            foreach (Express dr in dt)
            {
                expressListItems.Add(new SelectListItem() { Text = dr.title, Value = dr.id.ToString() });
            }
            ViewData["expressListItems"] = expressListItems;
        }
        #endregion
    }
}
